<template>
    <a-card :bordered="false">

    <!-- 左侧面板 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="12">
          <a-col :md="7" :sm="8">
            <a-form-item>
              <a-select v-model="queryParam.brandId" placeholder="品牌" show-search allowClear>
                <a-select-option :value="item.id.toString()" v-for="item in brandList" :key="item.id"> {{ item.brandName }} </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="7" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary"  icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
      <div class="table-operator" style="border-top: 5px">
        <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      </div>
       <a-table
        ref="table"
        :scroll="{x: 1700}"
        rowKey="id"
        size="middle"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :pagination="ipagination"
        @change="handleTableChange">
        <span  slot="status" slot-scope="text, record">   
           <a-switch :checked="record.status == 0" @click="updateBrandStatus(record,$event ? ischoose : noChoose)"></a-switch> {{record.statusText}}
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)"><a-icon type="edit"/> 编辑 </a>
          <a @click="decorations(record)"><a-icon type="edit"/> 装修 </a>
          <a-popconfirm title="确定删除吗?" @confirm="() =>handleDelete(record.id)">
            <a> 删除 </a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <decorationsModal ref='modalForm' @ok="modalFormOk"></decorationsModal>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import decorationsModal from './modules/decorationsModal'
import { filterObj } from '@/utils/util';
import { brandList,saveOrUpdateRenovation} from '@/api/marketingCenter/newmember'

export default {
  mixins:[JeecgListMixin],
  components: {decorationsModal},
  data() {
    return {
      brandList: [],
      ischoose: 0,
      noChoose: 1,
      description: '这是数据商品页面',
      visible: false,
      // 查询条件
      queryParam: {},
      dataSource:[{
        id:1,
        name:"134"
      }],
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 120,
          align: "center",
          customRender: function (t, r, index) {
              console.log(index);
            return parseInt(index) + 1;
          }
        },
        {
          title: '标题名称',
          align: "center",
          dataIndex: 'title',
        },
        {
          title: '品牌',
          align: "center",
          dataIndex: 'brandText',
        },
        {
          title: '备注',
          align: "center",
          dataIndex: 'remark',
        },
        {
          title: '状态',
          align: "center",
          dataIndex: 'status',
          scopedSlots: {customRender: 'status'},
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'},
          fixed:'right',
          width:150
        }
      ],
      url: {
        list: "/backend/vip/invite/pageRenovationVo",
        delete: "/backend/vip/invite/delRenovationById",
      },
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getBrandList()
  },
  methods: {
    //品牌下拉
    getBrandList() {
      brandList({
        current: 0,
        size: 99,
        state: 1
      })
        .then(res => {
          if (res.code === 200) {
            this.brandList = res.data
          } else {
            this.$message.error(res.msg || res.message)
          }
        })
        .catch(err => {})
    },
    //装修跳转
    decorations(record){
      localStorage.setItem('decorationsTitle', record.title)
      localStorage.setItem('decorationsBrandId', record.brandId)
      this.$router.push(`/marketingCenter/newmember/spruce/${record.id}`)
    },
    getQueryParams(){
      var param = Object.assign(this.queryParam);
      param.current = this.ipagination.current;
      param.size = this.ipagination.pageSize;
      return filterObj(param);
    },
    //修改状态
    updateBrandStatus(row,event){
      let params={
        id:row.id,
        brandId:row.brandId,
        status:event,
        // statusText:"状态"
      }
      saveOrUpdateRenovation(params).then(res=>{
        if (res.success) {
          this.$message.success(res.msg)
          this.loadData(1)
        } else {
          this.$message.warning(res.msg)
        }
      })
    },
    // 重置搜索框的内容
    searchReset() {
      var that = this;
      that.queryParam.brandId = "";
      that.loadData(this.ipagination.current);
    },
  },
}
</script>
<style scoped>
.thumbnail {
  width: 100px;
  height: 100px;
}
</style>